Socket
Socket
Sign inDemoInstall

@apollo/utils.keyvaluecache

Package Overview
Dependencies
Maintainers
4
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollo/utils.keyvaluecache

Minimal key-value cache interface


Version published
Maintainers
4
Created

What is @apollo/utils.keyvaluecache?

@apollo/utils.keyvaluecache is a utility package provided by Apollo that offers a simple and efficient key-value caching mechanism. It is designed to be used in conjunction with Apollo Server and other Apollo tools to improve performance by caching frequently accessed data.

What are @apollo/utils.keyvaluecache's main functionalities?

Basic Key-Value Storage

This feature allows you to store and retrieve key-value pairs in an in-memory cache. The example demonstrates setting a value for a key and then retrieving it.

const { InMemoryLRUCache } = require('@apollo/utils.keyvaluecache');

const cache = new InMemoryLRUCache();

async function cacheData() {
  await cache.set('key', 'value');
  const value = await cache.get('key');
  console.log(value); // Outputs: 'value'
}

cacheData();

Expiration Time

This feature allows you to set a time-to-live (TTL) for cached items. The example demonstrates setting a value with a TTL of 1 second and then attempting to retrieve it after 2 seconds, resulting in a null value.

const { InMemoryLRUCache } = require('@apollo/utils.keyvaluecache');

const cache = new InMemoryLRUCache();

async function cacheDataWithTTL() {
  await cache.set('key', 'value', { ttl: 1 }); // TTL in seconds
  setTimeout(async () => {
    const value = await cache.get('key');
    console.log(value); // Outputs: null
  }, 2000);
}

cacheDataWithTTL();

Deleting Cache Entries

This feature allows you to delete specific entries from the cache. The example demonstrates setting a value, deleting it, and then attempting to retrieve it, resulting in a null value.

const { InMemoryLRUCache } = require('@apollo/utils.keyvaluecache');

const cache = new InMemoryLRUCache();

async function deleteCacheEntry() {
  await cache.set('key', 'value');
  await cache.delete('key');
  const value = await cache.get('key');
  console.log(value); // Outputs: null
}

deleteCacheEntry();

Other packages similar to @apollo/utils.keyvaluecache

Keywords

FAQs

Package last updated on 23 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc